package ink.sunflowerk.config;

import ink.sunflowerk.exception.UserLoginException;
import org.springframework.web.servlet.HandlerInterceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * @author zhaokuii11@163.com
 * @create 2021-12-16 16:54
 * @Description
 */
public class UserLoginInterceptor implements HandlerInterceptor {
    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
        Object user = request.getSession().getAttribute("user");
        if (user == null) {
            throw new UserLoginException("必须登录才能执行");
        }
        return true;
    }
}
